MSDN

WinINet API Reference

The WinINet (Windows Internet) API provides high-level functions for interacting with HTTP and FTP protocols. It is primarily intended for client applications requiring Internet functionality.

Functions

InternetOpen

Initializes an application's use of WinINet functions.

InternetConnect

Creates a connection handle for an HTTP server.

HttpOpenRequest

Creates an HTTP request handle.

HttpSendRequest

Sends the specified request to the HTTP server.

InternetReadFile

Reads data from a handle opened by WinINet.

InternetCloseHandle

Closes an Internet handle.

InternetSetOption

Sets an Internet option on a handle.

InternetGetLastResponseInfo

Retrieves the last response code from an HTTP request.

Structures

typedef struct {
    DWORD   dwFlags;
    DWORD   dwTimeout;
    DWORD   dwRetryInterval;
    DWORD   dwCacheTimeout;
} INTERNET_BUFFERS;
    

Used to specify buffer information for reading and writing data.

Constants

Code Sample – Simple HTTP GET

#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")

int main() {
    HINTERNET hSession = InternetOpen(L"MyApp",
        INTERNET_OPEN_TYPE_PRECONFIG,
        NULL, NULL, 0);
    if (!hSession) return 1;

    HINTERNET hConnect = InternetConnect(hSession,
        L"example.com", INTERNET_DEFAULT_HTTP_PORT,
        NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
    if (!hConnect) { InternetCloseHandle(hSession); return 1; }

    HINTERNET hRequest = HttpOpenRequest(hConnect,
        L"GET", L"/", NULL, NULL, NULL,
        INTERNET_FLAG_RELOAD, 0);
    if (!hRequest) { InternetCloseHandle(hConnect); InternetCloseHandle(hSession); return 1; }

    if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0)) {
        InternetCloseHandle(hRequest);
        InternetCloseHandle(hConnect);
        InternetCloseHandle(hSession);
        return 1;
    }

    char buffer[4096];
    DWORD bytesRead;
    while (InternetReadFile(hRequest, buffer, sizeof(buffer) - 1, &bytesRead) && bytesRead) {
        buffer[bytesRead] = 0;
        printf("%s", buffer);
    }

    InternetCloseHandle(hRequest);
    InternetCloseHandle(hConnect);
    InternetCloseHandle(hSession);
    return 0;
}

This example demonstrates opening a session, connecting to example.com, sending a GET request, and printing the response.